//#include "stm32f4xx_hal.h"
//#include "graphic_def.h"

//#include "base_drv/referee.h"
//#include "base_drv/drv_uart.h"
//#include "base_drv/super_cap.h"
//#include "algorithm/crc.h"

//#include "vision.h"
//#include "algorithm/imu_fusion.h"
//#include "algorithm/util.h"

//#include <math.h>
//#include <string.h>
//#include "chassis.h"

//#define UI_HUART huart6
//#define UI_UART_SEND uart_send_async

//extern UART_HandleTypeDef UI_HUART;

//#define BAR_LEFT 760
//#define BAR_LEN 400
//#define BAR_RIGHT (BAR_LEFT+BAR_LEN)
//#define BAR_HORIZ 130
//#define BAR_WIDTH 9
//#define MARGIN 4

//#define HP_BAR_LEFT 910																			
//#define HP_BAR_LEN 300
//#define HP_BAR_HORIZ 800
//#define HP_BAR_WIDTH 8

//#define MIDDLE_X 960
//#define MIDDLE_Y 540


//#define LONG_BRANCH 30
//#define SHORT_BRANCH 15
//#define CHASSIS_DIR_X 960
//#define CHASSIS_DIR_Y 70

//#define INDIC_HALF_WIDTH 7
//#define INDIC_LEN 7
//#define INDIC_MARGIN 10

//#define CHASSIS_STATE_BASE_POS_X 1330
//#define CHASSIS_STATE_BASE_POS_Y 200

//#define INDIC_Y_OFFSET (CHASSIS_STATE_BASE_POS_Y - INDIC_HALF_WIDTH)

//char state_text[30] = "CVR X\nNOBUF\nSMALLBUF\nBIGBUF";
//static uint8_t tx_buffer[128];
//char spin_state_text[30] = "SPIN";
//char fric_state_text[30] = "FRIC";
//char cover_text[30]="OPEN!";
//char super_cap_text[30]="LOW!!!";
////ext_client_custom_graphic_seven_t test_data;
//ext_client_custom_graphic_single_t test_data;

//ext_client_custom_graphic_double_t voltage_bar_data;
//ext_client_custom_graphic_double_t chassis_dir_data;
//ext_client_custom_graphic_double_t aim_tracer_data;
//ext_client_custom_graphic_single_t state_indicator;
//ext_client_custom_graphic_single_t air_factor_data;
//ext_client_custom_graphic_double_t spin_fric_dot;

//ext_client_custom_graphic_double_t enemy_HP_data;
//ext_client_custom_graphic_single_t enemy_HP_num;
//ext_client_custom_graphic_single_t ammo;
//ext_client_custom_graphic_single_t vision_ref_data;
//ext_client_custom_graphic_single_t battle_45degree;
//ext_client_custom_graphic_single_t cover;

//ext_client_custom_graphic_five_t dynamic_layer_data;
//ext_client_custom_graphic_five_t dynamic_layer_data_extra;

//ext_client_custom_graphic_seven_t grenade_aim;
//ext_client_custom_graphic_seven_t dynamic_layer_data_grenade;

//ext_client_custom_character_t char_data;
//ext_client_custom_graphic_single_t hurt_pos_data;
//ext_client_custom_graphic_single_t shoot_speed;

//ext_client_custom_graphic_delete_t delete_data;



//extern vision_ctrl_t vision_ctrl_data;
//extern uint8_t cover_state;
//extern uint8_t fric_state;
//extern cap_data_t cap_data;
//extern uint8_t motor_state;
//extern chassis_spin_t chassis_spin_state;
//extern ext_game_robot_HP_t game_robot_HP;
//extern uint8_t battle_45degreee;
//extern uint8_t current_shoot_quantity;
//float shoot_speed_set_ui;


//uint16_t indicator_y = INDIC_Y_OFFSET;
//uint16_t robot_HP_data_RED[7];
//uint16_t robot_HP_data_BLUE[7];
//uint16_t RED_outpost;
//uint16_t BLUE_outpost;
//uint16_t robot_HP_max_RED[7];
//uint16_t robot_HP_max_BLUE[7];
//uint16_t show_robot_HP;
//uint16_t show_robot_HP_max;

////目录
////   init部分
////   -HP_input  CHAR  spin_fric_dot   grenade_aim  enemy_HP_data  voltage_bar_data
////   delete部分    init部分
////   update_background部分   
////   -votage  HP  char
////   update_ui部分
////   


//uint16_t fill_tx_buffer(uint8_t *p_data, uint16_t len)
//{
//  memset(tx_buffer, 0, 128);
//	
//  uint16_t total_size;
//  frame_header_t p_header;
//	
//  p_header.sof          = 0xA5;
//  p_header.data_len   = len;
//	p_header.seq 		= 0;
//	p_header.crc8 =  Get_CRC8_Check_Sum((uint8_t*)&p_header, sizeof(frame_header_t)-1, 0xff);
//  memcpy(&tx_buffer, &p_header, sizeof(frame_header_t));

//  //uint16_t cmd_id = 0x0301;
//  //memcpy(&tx_buffer[sizeof(frame_header_t)], (uint8_t*)&cmd_id, sizeof(uint16_t));
//  *(uint16_t*)&tx_buffer[sizeof(frame_header_t)] = 0x0301;
//  
//  memcpy(&tx_buffer[sizeof(frame_header_t) + sizeof(uint16_t)], p_data, len);

//  total_size = sizeof(frame_header_t) + sizeof(uint16_t) + len + sizeof(uint16_t);
//  Append_CRC16_Check_Sum(tx_buffer,total_size);
//  return total_size;
//}


//void set_indicator_color(uint32_t color){
//	dynamic_layer_data.grapic_data_struct[3].color = color;
//}


//void set_indicator(uint8_t chassis_mode, uint8_t energy_mode){
//		indicator_y = INDIC_Y_OFFSET - 26 - energy_mode * 24;
//}  //这个干什么用的

//void char_data_init(){

//	char_data.grapic_data_struct.graphic_name[0] = 0x20;
//	char_data.grapic_data_struct.graphic_name[1] = 0x22;
//	char_data.grapic_data_struct.graphic_name[2] = 0x20;
//	
//	char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	char_data.grapic_data_struct.graphic_tpye = GRAPHIC_CHAR; //0-line 2- circle 7-char
//	char_data.grapic_data_struct.layer = TEXT_LAYER;
//	char_data.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	char_data.grapic_data_struct.start_angle = 16;
//	char_data.grapic_data_struct.end_angle = strlen(state_text);
//	char_data.grapic_data_struct.width = 2;
//	//(100,960)
//	char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
//	char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y;
//	char_data.grapic_data_struct.radius = 0;
//	char_data.grapic_data_struct.end_x =  0;
//	char_data.grapic_data_struct.end_y = 0; //350 +300

//}


//void ammo_init(){              //火力初始化
//	//整型数
//	uint16_t total_len=0;
//	ammo.grapic_data_struct.graphic_name[0] = 0x20;
//	ammo.grapic_data_struct.graphic_name[1] = 0x11;
//	ammo.grapic_data_struct.graphic_name[2] = 0x12;

//	ammo.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	ammo.grapic_data_struct.graphic_tpye = 6; //0-line 2- circle 7-char
//	ammo.grapic_data_struct.layer = DYNAMIC_LAYER;
//	ammo.grapic_data_struct.color = COLOR_CYAN; //2/6-green,1-yellow,0-main,3-orange
//	ammo.grapic_data_struct.start_angle = 40;
//	ammo.grapic_data_struct.end_angle = 0;
//	ammo.grapic_data_struct.width = 4;

//	ammo.grapic_data_struct.start_x = 910;
//	ammo.grapic_data_struct.start_y = 700;
//	ammo.grapic_data_struct.radius = 0;
//	ammo.grapic_data_struct.end_x = 0;
//	ammo.grapic_data_struct.end_y = 0;
//	
//	ammo.header.data_cmd_id = 0x110; //绘制字符
//	ammo.header.sender_ID = game_robot_status.robot_id;
//	ammo.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	ammo.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
// //2/6-green,1-yellow,0-main,3-orange
//	ammo.grapic_data_struct.radius=current_shoot_quantity;
//	total_len = fill_tx_buffer((uint8_t*)&ammo,sizeof(ammo));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//}

//void shoot_speed_init(){         //射速初始化
//	//浮点数
//	uint16_t total_len=0;
//	shoot_speed.grapic_data_struct.graphic_name[0] = 0x20;
//	shoot_speed.grapic_data_struct.graphic_name[1] = 0x09;
//	shoot_speed.grapic_data_struct.graphic_name[2] = 0x12;

//	shoot_speed.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	shoot_speed.grapic_data_struct.graphic_tpye = 5; //0-line 2- circle 7-char
//	shoot_speed.grapic_data_struct.layer = DYNAMIC_LAYER;
//	shoot_speed.grapic_data_struct.color = COLOR_CYAN; //2/6-green,1-yellow,0-main,3-orange
//	shoot_speed.grapic_data_struct.start_angle = 40;
//	shoot_speed.grapic_data_struct.end_angle = 2;
//	shoot_speed.grapic_data_struct.width = 4;

//	shoot_speed.grapic_data_struct.start_x = 1700;
//	shoot_speed.grapic_data_struct.start_y = 540;
//	shoot_speed.grapic_data_struct.radius = 0;
//	shoot_speed.grapic_data_struct.end_x = 0;
//	shoot_speed.grapic_data_struct.end_y = 0;
//	
//	shoot_speed.header.data_cmd_id = 0x110; //绘制字符
//	shoot_speed.header.sender_ID = game_robot_status.robot_id;
//	shoot_speed.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	shoot_speed.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
// //2/6-green,1-yellow,0-main,3-orange
//	shoot_speed.grapic_data_struct.radius=shoot_speed_set_ui*10;
//	total_len = fill_tx_buffer((uint8_t*)&shoot_speed,sizeof(shoot_speed));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//}


//void spin_fric_dot_init(){       //小陀螺、摩擦轮初始化
//	spin_fric_dot.grapic_data_struct[0].graphic_name[0] = 0x22;
//	spin_fric_dot.grapic_data_struct[0].graphic_name[1] = 0x21;
//	spin_fric_dot.grapic_data_struct[0].graphic_name[2] = 0x22;
//	//小陀螺指示器
//	spin_fric_dot.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	spin_fric_dot.grapic_data_struct[0].graphic_tpye = GRAPHIC_CIRCLE; //0-line 2- circle 7-char
//	spin_fric_dot.grapic_data_struct[0].layer = DYNAMIC_LAYER;
//	spin_fric_dot.grapic_data_struct[0].color = COLOR_ORANGE; //2/6-green,1-yellow,0-main,3-orange
//	spin_fric_dot.grapic_data_struct[0].start_angle = 0;
//	spin_fric_dot.grapic_data_struct[0].end_angle = 0;
//	spin_fric_dot.grapic_data_struct[0].width = 10;

//	spin_fric_dot.grapic_data_struct[0].start_x = 680;
//	spin_fric_dot.grapic_data_struct[0].start_y = 680;
//	spin_fric_dot.grapic_data_struct[0].radius = 15;
//	spin_fric_dot.grapic_data_struct[0].end_x = 0;
//	spin_fric_dot.grapic_data_struct[0].end_y = 0;
//	memcpy(&dynamic_layer_data_extra.grapic_data_struct[0]
//	  ,&spin_fric_dot.grapic_data_struct[0],sizeof(graphic_data_struct_t));
//	
//	spin_fric_dot.grapic_data_struct[1].graphic_name[0] = 0x22;
//	spin_fric_dot.grapic_data_struct[1].graphic_name[1] = 0x21;
//	spin_fric_dot.grapic_data_struct[1].graphic_name[2] = 0x20;
//	
//	spin_fric_dot.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	spin_fric_dot.grapic_data_struct[1].graphic_tpye = GRAPHIC_CIRCLE; //0-line 2- circle 7-char
//	spin_fric_dot.grapic_data_struct[1].layer = DYNAMIC_LAYER;
//	spin_fric_dot.grapic_data_struct[1].color = COLOR_ORANGE; //2/6-green,1-yellow,0-main,3-orange
//	spin_fric_dot.grapic_data_struct[1].start_angle = 0;
//	spin_fric_dot.grapic_data_struct[1].end_angle = 0;
//	spin_fric_dot.grapic_data_struct[1].width = 10;

//	spin_fric_dot.grapic_data_struct[1].start_x = 680;
//	spin_fric_dot.grapic_data_struct[1].start_y = 400;
//	spin_fric_dot.grapic_data_struct[1].radius = 15;
//	spin_fric_dot.grapic_data_struct[1].end_x = 0;
//	spin_fric_dot.grapic_data_struct[1].end_y = 0;
//	memcpy(&dynamic_layer_data_extra.grapic_data_struct[1]
//		,&spin_fric_dot.grapic_data_struct[1],sizeof(graphic_data_struct_t));
//	


////榴弹指示器
//}
//void grenade_aim_init(){
//  grenade_aim.grapic_data_struct[0].graphic_name[0] = 0x22;
//	grenade_aim.grapic_data_struct[0].graphic_name[1] = 0x22;
//	grenade_aim.grapic_data_struct[0].graphic_name[2] = 0x22;
//	//最大横线左
//	grenade_aim.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	grenade_aim.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	grenade_aim.grapic_data_struct[0].layer = DYNAMIC_LAYER;
//	grenade_aim.grapic_data_struct[0].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	grenade_aim.grapic_data_struct[0].start_angle = 0;
//	grenade_aim.grapic_data_struct[0].end_angle = 0;
//	grenade_aim.grapic_data_struct[0].width = 5;

//	grenade_aim.grapic_data_struct[0].start_x = 800;
//	grenade_aim.grapic_data_struct[0].start_y = 450;
//	grenade_aim.grapic_data_struct[0].radius =0;
//	grenade_aim.grapic_data_struct[0].end_x = 930;
//	grenade_aim.grapic_data_struct[0].end_y = 450;
//	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[0]
//		,&grenade_aim.grapic_data_struct[0],sizeof(graphic_data_struct_t));
//	
//	grenade_aim.grapic_data_struct[1].graphic_name[0] = 0x17;
//	grenade_aim.grapic_data_struct[1].graphic_name[1] = 0x22;
//	grenade_aim.grapic_data_struct[1].graphic_name[2] = 0x22;
//	//最大横线右
//	grenade_aim.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	grenade_aim.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	grenade_aim.grapic_data_struct[1].layer = DYNAMIC_LAYER;
//	grenade_aim.grapic_data_struct[1].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	grenade_aim.grapic_data_struct[1].start_angle = 0;
//	grenade_aim.grapic_data_struct[1].end_angle = 0;
//	grenade_aim.grapic_data_struct[1].width = 5;

//	grenade_aim.grapic_data_struct[1].start_x = 1120;
//	grenade_aim.grapic_data_struct[1].start_y = 450;
//	grenade_aim.grapic_data_struct[1].radius =0;
//	grenade_aim.grapic_data_struct[1].end_x = 990;
//	grenade_aim.grapic_data_struct[1].end_y = 450;
//	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[1]
//		,&grenade_aim.grapic_data_struct[1],sizeof(graphic_data_struct_t));
//	

//	grenade_aim.grapic_data_struct[2].graphic_name[0] = 0x20;
//	grenade_aim.grapic_data_struct[2].graphic_name[1] = 0x22;
//	grenade_aim.grapic_data_struct[2].graphic_name[2] = 0x22;
//	//第二大横线
//	grenade_aim.grapic_data_struct[2].operate_tpye = OP_TYPE_ADD;
//	grenade_aim.grapic_data_struct[2].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	grenade_aim.grapic_data_struct[2].layer = DYNAMIC_LAYER;
//	grenade_aim.grapic_data_struct[2].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	grenade_aim.grapic_data_struct[2].start_angle = 0;
//	grenade_aim.grapic_data_struct[2].end_angle = 0;
//	grenade_aim.grapic_data_struct[2].width = 5;

//	grenade_aim.grapic_data_struct[2].start_x = 890;
//	grenade_aim.grapic_data_struct[2].start_y = 400;
//	grenade_aim.grapic_data_struct[2].radius = 0;
//	grenade_aim.grapic_data_struct[2].end_x = 1030;
//	grenade_aim.grapic_data_struct[2].end_y = 400;
//	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[2]
//		,&grenade_aim.grapic_data_struct[2],sizeof(graphic_data_struct_t));

//		
//	grenade_aim.grapic_data_struct[3].graphic_name[0] = 0x19; 
//	grenade_aim.grapic_data_struct[3].graphic_name[1] = 0x22;
//	grenade_aim.grapic_data_struct[3].graphic_name[2] = 0x22;
//  //第三大横线
//	grenade_aim.grapic_data_struct[3].operate_tpye = OP_TYPE_ADD;
//	grenade_aim.grapic_data_struct[3].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	grenade_aim.grapic_data_struct[3].layer = DYNAMIC_LAYER;
//	grenade_aim.grapic_data_struct[3].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	grenade_aim.grapic_data_struct[3].start_angle = 0;
//	grenade_aim.grapic_data_struct[3].end_angle = 0;
//	grenade_aim.grapic_data_struct[3].width = 5;

//	grenade_aim.grapic_data_struct[3].start_x = 905;
//	grenade_aim.grapic_data_struct[3].start_y = 350;
//	grenade_aim.grapic_data_struct[3].radius = 0;
//	grenade_aim.grapic_data_struct[3].end_x = 1015;
//	grenade_aim.grapic_data_struct[3].end_y = 350;
//	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[3]
//		,&grenade_aim.grapic_data_struct[3],sizeof(graphic_data_struct_t));
//	
//	grenade_aim.grapic_data_struct[4].graphic_name[0] = 0x18;
//	grenade_aim.grapic_data_struct[4].graphic_name[1] = 0x22;
//	grenade_aim.grapic_data_struct[4].graphic_name[2] = 0x22;
//	//第四大横线
//	grenade_aim.grapic_data_struct[4].operate_tpye = OP_TYPE_ADD;
//	grenade_aim.grapic_data_struct[4].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	grenade_aim.grapic_data_struct[4].layer = DYNAMIC_LAYER;
//	grenade_aim.grapic_data_struct[4].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	grenade_aim.grapic_data_struct[4].start_angle = 0;
//	grenade_aim.grapic_data_struct[4].end_angle = 0;
//	grenade_aim.grapic_data_struct[4].width = 5;

//	grenade_aim.grapic_data_struct[4].start_x = 925;
//	grenade_aim.grapic_data_struct[4].start_y =300;
//	grenade_aim.grapic_data_struct[4].radius = 0;
//	grenade_aim.grapic_data_struct[4].end_x = 995;
//	grenade_aim.grapic_data_struct[4].end_y = 300;
//	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[4]
//		,&grenade_aim.grapic_data_struct[4],sizeof(graphic_data_struct_t));
//		
//	
//	//第五大横线
//	grenade_aim.grapic_data_struct[5].graphic_name[0] = 0x16;
//	grenade_aim.grapic_data_struct[5].graphic_name[1] = 0x22;
//	grenade_aim.grapic_data_struct[5].graphic_name[2] = 0x22;
//	grenade_aim.grapic_data_struct[5].operate_tpye = OP_TYPE_ADD;
//	grenade_aim.grapic_data_struct[5].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	grenade_aim.grapic_data_struct[5].layer = DYNAMIC_LAYER;
//	grenade_aim.grapic_data_struct[5].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	grenade_aim.grapic_data_struct[5].start_angle = 0;
//	grenade_aim.grapic_data_struct[5].end_angle = 0;
//	grenade_aim.grapic_data_struct[5].width = 5;

//	grenade_aim.grapic_data_struct[5].start_x = 940;
//	grenade_aim.grapic_data_struct[5].start_y =250;
//	grenade_aim.grapic_data_struct[5].radius = 0;
//	grenade_aim.grapic_data_struct[5].end_x = 980;
//	grenade_aim.grapic_data_struct[5].end_y = 250;
//	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[5]
//		,&grenade_aim.grapic_data_struct[5],sizeof(graphic_data_struct_t));

//    //斜45度
////	battle_45degree.grapic_data_struct.graphic_name[0] = 0x01;
////	battle_45degree.grapic_data_struct.graphic_name[1] = 0x01;
////	battle_45degree.grapic_data_struct.graphic_name[2] = 0x22;
////	battle_45degree.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
////	battle_45degree.grapic_data_struct.graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
////	battle_45degree.grapic_data_struct.layer = DYNAMIC_LAYER;
////	battle_45degree.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
////	battle_45degree.grapic_data_struct.start_angle = 0;
////	battle_45degree.grapic_data_struct.end_angle = 0;
////	battle_45degree.grapic_data_struct.width = 5;

////	battle_45degree.grapic_data_struct.start_x = 960;
////	battle_45degree.grapic_data_struct.start_y =400;
////	battle_45degree.grapic_data_struct.radius = 0;
////	battle_45degree.grapic_data_struct.end_x = 960;
////	battle_45degree.grapic_data_struct.end_y = 150;
//	
//}

//void voltage_bar_data_init(){

//	//新ui
//	voltage_bar_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	voltage_bar_data.grapic_data_struct[0].graphic_tpye = GRAPHIC_ARC;
//	voltage_bar_data.grapic_data_struct[0].layer = DYNAMIC_LAYER;
//	voltage_bar_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	voltage_bar_data.grapic_data_struct[0].start_angle = 60;//更改起始角度
//	voltage_bar_data.grapic_data_struct[0].end_angle = 120;//更改结束角度
//	voltage_bar_data.grapic_data_struct[0].width = BAR_WIDTH;
//	//(460,350)(460,650)
//	voltage_bar_data.grapic_data_struct[0].start_x = MIDDLE_X;
//	voltage_bar_data.grapic_data_struct[0].start_y = MIDDLE_Y;
//	voltage_bar_data.grapic_data_struct[0].radius = 0;
//	voltage_bar_data.grapic_data_struct[0].end_x = 350;
//	voltage_bar_data.grapic_data_struct[0].end_y = 350;
//	memcpy(&dynamic_layer_data.grapic_data_struct[0]
//		,&voltage_bar_data.grapic_data_struct[0],sizeof(graphic_data_struct_t));
//	
//	voltage_bar_data.grapic_data_struct[1].graphic_name[0] = 0x20;
//	voltage_bar_data.grapic_data_struct[1].graphic_name[1] = 0x21;
//	voltage_bar_data.grapic_data_struct[1].graphic_name[2] = 0x21;
//	
//	voltage_bar_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	voltage_bar_data.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	voltage_bar_data.grapic_data_struct[1].layer = BACKGROUND_LAYER;
//	voltage_bar_data.grapic_data_struct[1].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	voltage_bar_data.grapic_data_struct[1].start_angle = 0;
//	voltage_bar_data.grapic_data_struct[1].end_angle = 0;
//	voltage_bar_data.grapic_data_struct[1].width = 2;
//	voltage_bar_data.grapic_data_struct[1].start_x = (uint32_t)((350 + 10) * cosf(31*2*PI/360.0f) + MIDDLE_X);
//	voltage_bar_data.grapic_data_struct[1].start_y = (uint32_t)((350 + 10) * sinf(31*2*PI/360.0f) + MIDDLE_Y);
//	voltage_bar_data.grapic_data_struct[1].radius = 0;
//	voltage_bar_data.grapic_data_struct[1].end_x = (uint32_t)((350 - 10) * cosf(31*2*PI/360.0f) + MIDDLE_X);
//	voltage_bar_data.grapic_data_struct[1].end_y = (uint32_t)((350 - 10) * sinf(31*2*PI/360.0f) + MIDDLE_Y);
//	
//	chassis_dir_data.grapic_data_struct[0].graphic_name[0] = 0x20;
//	chassis_dir_data.grapic_data_struct[0].graphic_name[1] = 0x21;
//	chassis_dir_data.grapic_data_struct[0].graphic_name[2] = 0x22;
//	
//	chassis_dir_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	chassis_dir_data.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	chassis_dir_data.grapic_data_struct[0].layer = DYNAMIC_LAYER;
//	chassis_dir_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	chassis_dir_data.grapic_data_struct[0].start_angle = 0;
//	chassis_dir_data.grapic_data_struct[0].end_angle = 0;
//	chassis_dir_data.grapic_data_struct[0].width = 2;
//	chassis_dir_data.grapic_data_struct[0].start_x = CHASSIS_DIR_X;
//	chassis_dir_data.grapic_data_struct[0].start_y = CHASSIS_DIR_Y + LONG_BRANCH;
//	chassis_dir_data.grapic_data_struct[0].radius = 0;
//	chassis_dir_data.grapic_data_struct[0].end_x = CHASSIS_DIR_X;
//	chassis_dir_data.grapic_data_struct[0].end_y = CHASSIS_DIR_Y - SHORT_BRANCH;
//	
//	
//	chassis_dir_data.grapic_data_struct[1].graphic_name[0] = 0x20;
//	chassis_dir_data.grapic_data_struct[1].graphic_name[1] = 0x21;
//	chassis_dir_data.grapic_data_struct[1].graphic_name[2] = 0x23;
//	
//	chassis_dir_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	chassis_dir_data.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	chassis_dir_data.grapic_data_struct[1].layer = DYNAMIC_LAYER;
//	chassis_dir_data.grapic_data_struct[1].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	chassis_dir_data.grapic_data_struct[1].start_angle = 0;
//	chassis_dir_data.grapic_data_struct[1].end_angle = 0;
//	chassis_dir_data.grapic_data_struct[1].width = 3;
//	chassis_dir_data.grapic_data_struct[1].start_x = (CHASSIS_DIR_X - LONG_BRANCH);
//	chassis_dir_data.grapic_data_struct[1].start_y = CHASSIS_DIR_Y;
//	chassis_dir_data.grapic_data_struct[1].radius = 0;
//	chassis_dir_data.grapic_data_struct[1].end_x = CHASSIS_DIR_X + LONG_BRANCH;
//	chassis_dir_data.grapic_data_struct[1].end_y = CHASSIS_DIR_Y;
//	memcpy(&dynamic_layer_data.grapic_data_struct[1]
//		,&chassis_dir_data.grapic_data_struct[0],sizeof(graphic_data_struct_t));
//	memcpy(&dynamic_layer_data.grapic_data_struct[2]
//		,&chassis_dir_data.grapic_data_struct[1],sizeof(graphic_data_struct_t));

//	
//	state_indicator.grapic_data_struct.graphic_name[0] = 0x20;
//	state_indicator.grapic_data_struct.graphic_name[1] = 0x21;
//	state_indicator.grapic_data_struct.graphic_name[2] = 0x24;
//	
//	state_indicator.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	state_indicator.grapic_data_struct.graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
//	state_indicator.grapic_data_struct.layer = DYNAMIC_LAYER;
//	state_indicator.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	state_indicator.grapic_data_struct.start_angle = 0;
//	state_indicator.grapic_data_struct.end_angle = 0;
//	state_indicator.grapic_data_struct.width = (INDIC_HALF_WIDTH*2);
//	//(460,350)(460,650)
//	state_indicator.grapic_data_struct.start_x = (CHASSIS_STATE_BASE_POS_X - INDIC_MARGIN - INDIC_LEN);
//	state_indicator.grapic_data_struct.start_y = (CHASSIS_STATE_BASE_POS_Y - INDIC_HALF_WIDTH);
//	state_indicator.grapic_data_struct.radius = 0;
//	state_indicator.grapic_data_struct.end_x = (CHASSIS_STATE_BASE_POS_X - INDIC_MARGIN);
//	state_indicator.grapic_data_struct.end_y = (CHASSIS_STATE_BASE_POS_Y - INDIC_HALF_WIDTH);
//	memcpy(&dynamic_layer_data.grapic_data_struct[3]
//		,&state_indicator.grapic_data_struct,sizeof(graphic_data_struct_t));

//	vision_ref_data.grapic_data_struct.graphic_name[0] = 0x20;
//	vision_ref_data.grapic_data_struct.graphic_name[1] = 0x21;
//	vision_ref_data.grapic_data_struct.graphic_name[2] = 0x25;

//	vision_ref_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	vision_ref_data.grapic_data_struct.graphic_tpye = GRAPHIC_CIRCLE; //0-line 2- circle 7-char
//	vision_ref_data.grapic_data_struct.layer = DYNAMIC_LAYER;
//	vision_ref_data.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	vision_ref_data.grapic_data_struct.start_angle = 0;
//	vision_ref_data.grapic_data_struct.end_angle = 0;
//	vision_ref_data.grapic_data_struct.width = 3;
//	//(460,350)(460,650)
//	vision_ref_data.grapic_data_struct.start_x = MIDDLE_X;
//	vision_ref_data.grapic_data_struct.start_y = MIDDLE_Y;
//	vision_ref_data.grapic_data_struct.radius = 100;
//	vision_ref_data.grapic_data_struct.end_x = 0;
//	vision_ref_data.grapic_data_struct.end_y = 0;
//	memcpy(&dynamic_layer_data.grapic_data_struct[4]
//		,&vision_ref_data.grapic_data_struct,sizeof(graphic_data_struct_t));
//}


//void ui_graphic_delete(uint8_t operate_tpye, uint8_t layer){
//	uint16_t total_len = 0;
//	memset(&delete_data,0,sizeof(delete_data));
//	delete_data.header.data_cmd_id = 0x100;
//	delete_data.header.sender_ID = game_robot_status.robot_id;
//	delete_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	
//	delete_data.layer = layer;
//	delete_data.operate_tpye = operate_tpye;
//	
//	total_len = fill_tx_buffer((uint8_t*)&delete_data,sizeof(delete_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//}



//void init_ui_static(void){
//	memset(&voltage_bar_data,0,sizeof(voltage_bar_data));
//	//voltage_bar_data.grapic_data_struct[0]
//	voltage_bar_data_init();
//	char_data_init();
//	spin_fric_dot_init();
//	grenade_aim_init(); 
//	ammo_init();
//}

//void update_background(void){  //静态图层的设置
//	uint16_t total_len = 0;
//	voltage_bar_data.header.data_cmd_id = 0x102; 
//	voltage_bar_data.header.sender_ID = game_robot_status.robot_id;
//	voltage_bar_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	voltage_bar_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	voltage_bar_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	total_len = fill_tx_buffer((uint8_t*)&voltage_bar_data,sizeof(voltage_bar_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//  chassis_dir_data.header.data_cmd_id = 0x102;
//	chassis_dir_data.header.sender_ID = game_robot_status.robot_id;
//	chassis_dir_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	chassis_dir_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	chassis_dir_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	total_len = fill_tx_buffer((uint8_t*)&chassis_dir_data,sizeof(chassis_dir_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	
//	// spin_fric_dot.header.data_cmd_id = 0x102; //绘制两个图形
//	// spin_fric_dot.header.sender_ID = game_robot_status.robot_id;
//	// spin_fric_dot.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	// spin_fric_dot.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	// spin_fric_dot.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	// total_len = fill_tx_buffer((uint8_t*)&spin_fric_dot,sizeof(spin_fric_dot));
//	// UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	

//	
//	state_indicator.header.data_cmd_id = 0x101; //绘制一个图形
//	state_indicator.header.sender_ID = game_robot_status.robot_id;
//	state_indicator.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	state_indicator.grapic_data_struct.operate_tpye =OP_TYPE_ADD;
//	total_len = fill_tx_buffer((uint8_t*)&state_indicator,sizeof(state_indicator));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);

//	battle_45degree.header.data_cmd_id = 0x101; //绘制一个图形
//	battle_45degree.header.sender_ID = game_robot_status.robot_id;
//	battle_45degree.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	
//	if( battle_45degreee)
//	  battle_45degree.grapic_data_struct.operate_tpye =OP_TYPE_ADD;
//	else if(! battle_45degreee)
//		battle_45degree.grapic_data_struct.operate_tpye =OP_TYPE_DEL;
//	total_len = fill_tx_buffer((uint8_t*)&battle_45degree,sizeof(battle_45degree));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	char_data.header.data_cmd_id = 0x110; //绘制字符
//	char_data.header.sender_ID = game_robot_status.robot_id;
//	char_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	char_data.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	
//	//左侧小陀螺状态指示器
//	char_data.grapic_data_struct.graphic_name[2] = 0x23;
//	char_data.grapic_data_struct.start_x = 560;
//	char_data.grapic_data_struct.start_y = 680;
//	char_data.grapic_data_struct.start_angle = 20;
//	char_data.grapic_data_struct.end_angle = strlen(spin_state_text);
//	memset(char_data.data,0,30);
//	memcpy(char_data.data,spin_state_text,strlen(spin_state_text));
//	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	//左侧摩擦轮指示器
//	char_data.grapic_data_struct.graphic_name[2] = 0x24;
//	char_data.grapic_data_struct.start_x = 560;
//	char_data.grapic_data_struct.start_y = 400;
//	char_data.grapic_data_struct.start_angle = 20;
//	char_data.grapic_data_struct.end_angle = strlen(fric_state_text);
//	memset(char_data.data,0,30);
//	memcpy(char_data.data,fric_state_text,strlen(fric_state_text));
//	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	//弹舱盖指示器
//	char_data.grapic_data_struct.graphic_name[2] = 0x25;
//	char_data.grapic_data_struct.start_x = 1000;
//	char_data.grapic_data_struct.start_y = 300;
//	char_data.grapic_data_struct.start_angle = 100;
//	char_data.grapic_data_struct.end_angle = strlen(cover_text);
//	char_data.grapic_data_struct.width=10;
//	memset(char_data.data,0,30);
//	memcpy(char_data.data,cover_text,strlen(cover_text));
//	if(cover_state)
//		char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
//	else if(cover_state==0)
//		char_data.grapic_data_struct.operate_tpye = OP_TYPE_DEL;
//	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	char_data.grapic_data_struct.width=2;
//	char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;

//// //电容电压指示器
////  char_data.grapic_data_struct.graphic_name[2] = 0x26;
////	char_data.grapic_data_struct.start_x = 1000;
////	char_data.grapic_data_struct.start_y = 800;
////	char_data.grapic_data_struct.start_angle = 100;
////	char_data.grapic_data_struct.end_angle = strlen(super_cap_text);
////	memset(char_data.data,0,30);
////	memcpy(char_data.data,super_cap_text,strlen(super_cap_text));
////  if(cap_data.cap_voltage < 15.0f)
////		char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
////	else 
////		char_data.grapic_data_struct.operate_tpye = OP_TYPE_DEL;
////	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
////	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//  
// 
//  ammo.header.data_cmd_id = 0x110; //绘制字符
//	ammo.header.sender_ID = game_robot_status.robot_id;
//	ammo.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	ammo.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
// //2/6-green,1-yellow,0-main,3-orange
//	ammo.grapic_data_struct.radius = current_shoot_quantity;
//	total_len = fill_tx_buffer((uint8_t*)&ammo,sizeof(ammo));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	ammo.header.data_cmd_id = 0x110; //绘制字符
//	ammo.header.sender_ID = game_robot_status.robot_id;
//	ammo.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	ammo.grapic_data_struct.operate_tpye = OP_TYPE_MOD;
// //2/6-green,1-yellow,0-main,3-orange
//	ammo.grapic_data_struct.radius = current_shoot_quantity;
//	total_len = fill_tx_buffer((uint8_t*)&ammo,sizeof(ammo));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//}

//#define HURT_ARC_LEN 10


//void update_ui(float cap_voltage,float relative_angle,int32_t air_factor){
//	uint16_t total_len = 0;

//	dynamic_layer_data.header.data_cmd_id = 0x103;
//	dynamic_layer_data.header.sender_ID = game_robot_status.robot_id;
//	dynamic_layer_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	
//	dynamic_layer_data_extra.header.data_cmd_id = 0x103;
//	dynamic_layer_data_extra.header.sender_ID = game_robot_status.robot_id;
//	dynamic_layer_data_extra.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	
//	dynamic_layer_data_grenade.header.data_cmd_id = 0x104;
//	dynamic_layer_data_grenade.header.sender_ID = game_robot_status.robot_id;
//	dynamic_layer_data_grenade.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	
//	//dynamic_layer_data_grenade.grapic_data_struct[3].end_x=HP_BAR_LEFT+ ((show_robot_HP+0.01f) / (show_robot_HP_max+0.01f))*HP_BAR_LEN; 
//	
//	if(cap_voltage < 14.0f){
//		dynamic_layer_data.grapic_data_struct[0].color = COLOR_PURPLE; //2/6-green,1-yellow,0-main,3-orange
//	}else if(cap_voltage < 18.0f){
//		dynamic_layer_data.grapic_data_struct[0].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
//	}else{
//		dynamic_layer_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
//	}
//	LIMIT_MIN_MAX(cap_voltage, 12.0f, 24.5f);
//	LIMIT_MIN_MAX(cap_data.input_voltage, 20.0f, 25.0f);
//	dynamic_layer_data.grapic_data_struct[0].start_angle = (uint32_t)(120 - ((cap_voltage - 12.0f) / (cap_data.input_voltage - 14.1f))*60); //350 +300
//	LIMIT_MIN_MAX(dynamic_layer_data.grapic_data_struct[0].start_angle, 60, 120);
//	
//	dynamic_layer_data.grapic_data_struct[0].operate_tpye = OP_TYPE_MOD;
//	
//	float sin_ang = sinf(2*PI*relative_angle / 360.0f);
//	float cos_ang = cosf(2*PI*relative_angle / 360.0f);

//	dynamic_layer_data.grapic_data_struct[1].start_x = CHASSIS_DIR_X+sin_ang*LONG_BRANCH;
//	dynamic_layer_data.grapic_data_struct[1].start_y = CHASSIS_DIR_Y+cos_ang*LONG_BRANCH;
//	dynamic_layer_data.grapic_data_struct[1].end_x = CHASSIS_DIR_X-sin_ang*SHORT_BRANCH;
//	dynamic_layer_data.grapic_data_struct[1].end_y = CHASSIS_DIR_Y-cos_ang*SHORT_BRANCH;
//	
//	dynamic_layer_data.grapic_data_struct[2].start_x = CHASSIS_DIR_X-cos_ang*LONG_BRANCH;
//	dynamic_layer_data.grapic_data_struct[2].start_y = CHASSIS_DIR_Y+sin_ang*LONG_BRANCH;
//	dynamic_layer_data.grapic_data_struct[2].end_x = CHASSIS_DIR_X+cos_ang*LONG_BRANCH;
//	dynamic_layer_data.grapic_data_struct[2].end_y = CHASSIS_DIR_Y-sin_ang*LONG_BRANCH;
//	
//	dynamic_layer_data.grapic_data_struct[0].operate_tpye = OP_TYPE_MOD;

//	dynamic_layer_data.grapic_data_struct[1].operate_tpye = OP_TYPE_MOD;
//	dynamic_layer_data.grapic_data_struct[2].operate_tpye = OP_TYPE_MOD;
//	
//	dynamic_layer_data.grapic_data_struct[3].operate_tpye = OP_TYPE_MOD;
//	dynamic_layer_data.grapic_data_struct[3].color = COLOR_GREEN;
//	dynamic_layer_data.grapic_data_struct[3].start_y = indicator_y;
//	dynamic_layer_data.grapic_data_struct[3].end_y = indicator_y;
//	
//	dynamic_layer_data.grapic_data_struct[4].operate_tpye = OP_TYPE_MOD;
//	
//	//大型状态指示器
//	if(chassis_spin_state == SPINNING){
//		dynamic_layer_data_extra.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
//	}
//	else{
//		dynamic_layer_data_extra.grapic_data_struct[0].operate_tpye = OP_TYPE_DEL;
//	}
//	
//	if(fric_state)
//    dynamic_layer_data_extra.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
//	else if(!fric_state)
//	   dynamic_layer_data_extra.grapic_data_struct[1].operate_tpye = OP_TYPE_DEL;
//		
//	total_len = fill_tx_buffer((uint8_t*)&dynamic_layer_data_extra,sizeof(dynamic_layer_data_extra));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	total_len = fill_tx_buffer((uint8_t*)&dynamic_layer_data,sizeof(dynamic_layer_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	total_len = fill_tx_buffer((uint8_t*)&dynamic_layer_data_grenade,sizeof(dynamic_layer_data_grenade));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);

//	char_data.header.data_cmd_id = 0x110;
//	char_data.header.sender_ID = game_robot_status.robot_id;
//	char_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	char_data.grapic_data_struct.graphic_name[2] = 0x20;
//	char_data.grapic_data_struct.operate_tpye = OP_TYPE_MOD;
//	char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
//	char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y;
//	char_data.grapic_data_struct.start_angle = 16;
//	char_data.grapic_data_struct.end_angle = strlen(state_text);
//	if(cover_state) memcpy(state_text+4, "1", 1);
//	else memcpy(state_text+4, "0", 1);
//	memcpy(char_data.data,state_text,strlen(state_text));
//	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
//	
//	
//}

#include "stm32f4xx_hal.h"
#include "graphic_def.h"

#include "base_drv/referee.h"
#include "base_drv/drv_uart.h"
#include "base_drv/super_cap.h"
#include "algorithm/crc.h"

#include "vision.h"
#include "algorithm/imu_fusion.h"
#include "algorithm/util.h"

#include <math.h>
#include <string.h>
#include "chassis.h"

#define UI_HUART huart6
#define UI_UART_SEND uart_send_async

extern UART_HandleTypeDef UI_HUART;

#define BAR_LEFT 760
#define BAR_LEN 400
#define BAR_RIGHT (BAR_LEFT+BAR_LEN)
#define BAR_HORIZ 130
#define BAR_WIDTH 9
#define MARGIN 4

#define HP_BAR_LEFT 910																			
#define HP_BAR_LEN 300
#define HP_BAR_HORIZ 800
#define HP_BAR_WIDTH 8

#define MIDDLE_X 960
#define MIDDLE_Y 540


#define LONG_BRANCH 30
#define SHORT_BRANCH 15
#define CHASSIS_DIR_X 960
#define CHASSIS_DIR_Y 70

#define INDIC_HALF_WIDTH 7
#define INDIC_LEN 7
#define INDIC_MARGIN 10

#define CHASSIS_STATE_BASE_POS_X 1330
#define CHASSIS_STATE_BASE_POS_Y 200

#define INDIC_Y_OFFSET (CHASSIS_STATE_BASE_POS_Y - INDIC_HALF_WIDTH)

char state_text[30] = "CVR X\nNOBUF\nSMALLBUF\nBIGBUF";
static uint8_t tx_buffer[128];
char spin_state_text[30] = "SPIN";
char fric_state_text[30] = "FRIC";
char cover_text[30]="OPEN!";
//ext_client_custom_graphic_seven_t test_data;
ext_client_custom_graphic_single_t test_data;

ext_client_custom_graphic_double_t voltage_bar_data;
ext_client_custom_graphic_double_t chassis_dir_data;
ext_client_custom_graphic_double_t aim_tracer_data;
ext_client_custom_graphic_single_t state_indicator;
ext_client_custom_graphic_single_t air_factor_data;
ext_client_custom_graphic_double_t spin_fric_dot;
ext_client_custom_graphic_double_t grenade_aim;
ext_client_custom_graphic_double_t grenade_aim1;
ext_client_custom_graphic_double_t grenade_aim2;
ext_client_custom_graphic_double_t grenade_aim3;
ext_client_custom_graphic_double_t grenade_aim4;
ext_client_custom_graphic_double_t enemy_HP_data;
ext_client_custom_graphic_single_t enemy_HP_num;
ext_client_custom_graphic_single_t ammo;
ext_client_custom_graphic_single_t vision_ref_data;
ext_client_custom_graphic_single_t battle_45degree;
ext_client_custom_graphic_single_t cover;

ext_client_custom_graphic_five_t dynamic_layer_data;
ext_client_custom_graphic_five_t dynamic_layer_data_extra;
ext_client_custom_graphic_five_t dynamic_layer_data_grenade;
ext_client_custom_character_t char_data;
ext_client_custom_graphic_single_t hurt_pos_data;
ext_client_custom_graphic_single_t shoot_speed;

ext_client_custom_graphic_delete_t delete_data;



extern vision_ctrl_t vision_ctrl_data;
extern uint8_t cover_state;
extern uint8_t fric_state;
extern cap_data_t cap_data;
extern uint8_t motor_state;
extern chassis_spin_t chassis_spin_state;
extern ext_game_robot_HP_t game_robot_HP;
extern uint8_t battle_45degreee;
extern uint8_t current_shoot_quantity;
extern float shoot_speed_set;


uint16_t indicator_y = INDIC_Y_OFFSET;
uint16_t robot_HP_data_RED[7];
uint16_t robot_HP_data_BLUE[7];
uint16_t RED_outpost;
uint16_t BLUE_outpost;
uint16_t robot_HP_max_RED[7];
uint16_t robot_HP_max_BLUE[7];
uint16_t show_robot_HP;
uint16_t show_robot_HP_max;

//目录
//   init部分
//   -HP_input  CHAR  spin_fric_dot   grenade_aim  enemy_HP_data  voltage_bar_data
//   delete部分    init部分
//   update_background部分   
//   -votage  HP  char
//   update_ui部分
//   
void input_HP(){
  uint8_t i; 
	memcpy(robot_HP_data_RED, (void*)&(game_robot_HP.red_1_robot_HP),sizeof(uint16_t)*7);
	memcpy(robot_HP_data_BLUE, (void*)(&(game_robot_HP.red_1_robot_HP)+8),sizeof(uint16_t)*7);
	RED_outpost=game_robot_HP.red_outpost_HP;
	BLUE_outpost=game_robot_HP.blue_outpost_HP;
	

	//用一直更新的方法知道大概的血量上限
	for(i=0;i<7;i++){
		robot_HP_max_RED[i]=(robot_HP_max_RED[i]<robot_HP_data_RED[i])?robot_HP_data_RED[i]:robot_HP_max_RED[i];
		robot_HP_max_BLUE[i]=(robot_HP_max_BLUE[i]<robot_HP_data_BLUE[i])?robot_HP_data_BLUE[i]:robot_HP_max_BLUE[i];

		
	}

	
//	if(vision_ctrl_data.target_found){
//		if(vision_ctrl_data.number==1||vision_ctrl_data.number==3||vision_ctrl_data.number==4||vision_ctrl_data.number==5){
//			i=vision_ctrl_data.number;
//			
//		if(game_robot_status.robot_id >100){ //判断己方颜色 大于一百为蓝
//		
//	     show_robot_HP=robot_HP_data_RED[i-1];
//	     show_robot_HP_max=robot_HP_max_RED[i-1];
//	  }
//	    else{
//		   show_robot_HP=robot_HP_data_BLUE[i-1];
//	     show_robot_HP_max=robot_HP_max_BLUE[i-1];
//  }
//			
//			
//		}
//		else if(vision_ctrl_data.number==6)	{
//         if(game_robot_status.robot_id >100) show_robot_HP=robot_HP_data_RED[5];
//		else show_robot_HP=robot_HP_data_BLUE[5]; //哨兵
//			   
//			show_robot_HP_max=1000;
//		}	
//		
//		else if(vision_ctrl_data.number==7){ 
//			if(game_robot_status.robot_id >100)  show_robot_HP=RED_outpost;
//			else show_robot_HP=BLUE_outpost;
//			show_robot_HP_max=1500; //outpost max HP
//		}
//	  else{
//			 show_robot_HP=0; 
//       show_robot_HP_max=100;
//		}

//	}else{
//	
//			 show_robot_HP=0; 
//       show_robot_HP_max=100;
//		}
}


uint16_t fill_tx_buffer(uint8_t *p_data, uint16_t len)
{
  memset(tx_buffer, 0, 128);
	
  uint16_t total_size;
  frame_header_t p_header;
	
  p_header.sof          = 0xA5;
  p_header.data_len   = len;
	p_header.seq 		= 0;
	p_header.crc8 =  Get_CRC8_Check_Sum((uint8_t*)&p_header, sizeof(frame_header_t)-1, 0xff);
  memcpy(&tx_buffer, &p_header, sizeof(frame_header_t));

  //uint16_t cmd_id = 0x0301;
  //memcpy(&tx_buffer[sizeof(frame_header_t)], (uint8_t*)&cmd_id, sizeof(uint16_t));
  *(uint16_t*)&tx_buffer[sizeof(frame_header_t)] = 0x0301;
  
  memcpy(&tx_buffer[sizeof(frame_header_t) + sizeof(uint16_t)], p_data, len);

  total_size = sizeof(frame_header_t) + sizeof(uint16_t) + len + sizeof(uint16_t);
  Append_CRC16_Check_Sum(tx_buffer,total_size);
  return total_size;
}


void set_indicator_color(uint32_t color){
	dynamic_layer_data.grapic_data_struct[3].color = color;
}


void set_indicator(uint8_t chassis_mode, uint8_t energy_mode){
		indicator_y = INDIC_Y_OFFSET - 26 - energy_mode * 24;
}  //这个干什么用的

void char_data_init(){

	char_data.grapic_data_struct.graphic_name[0] = 0x20;
	char_data.grapic_data_struct.graphic_name[1] = 0x22;
	char_data.grapic_data_struct.graphic_name[2] = 0x20;
	
	char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	char_data.grapic_data_struct.graphic_tpye = GRAPHIC_CHAR; //0-line 2- circle 7-char
	char_data.grapic_data_struct.layer = TEXT_LAYER;
	char_data.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	char_data.grapic_data_struct.start_angle = 16;
	char_data.grapic_data_struct.end_angle = strlen(state_text);
	char_data.grapic_data_struct.width = 2;
	//(100,960)
	char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
	char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y;
	char_data.grapic_data_struct.radius = 0;
	char_data.grapic_data_struct.end_x =  0;
	char_data.grapic_data_struct.end_y = 0; //350 +300



}

void enemy_HP_num_init(){
	//整型数
	uint16_t total_len=0;
	enemy_HP_num.grapic_data_struct.graphic_name[0] = 0x10;
	enemy_HP_num.grapic_data_struct.graphic_name[1] = 0x25;
	enemy_HP_num.grapic_data_struct.graphic_name[2] = 0x12;
	//小陀螺指示器
	enemy_HP_num.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	enemy_HP_num.grapic_data_struct.graphic_tpye = 6; //0-line 2- circle 7-char
	enemy_HP_num.grapic_data_struct.layer = DYNAMIC_LAYER;
	enemy_HP_num.grapic_data_struct.color = COLOR_PINK; //2/6-green,1-yellow,0-main,3-orange
	enemy_HP_num.grapic_data_struct.start_angle = 40;
	enemy_HP_num.grapic_data_struct.end_angle = 0;
	enemy_HP_num.grapic_data_struct.width = 6;

	enemy_HP_num.grapic_data_struct.start_x = 750;
	enemy_HP_num.grapic_data_struct.start_y = 820;
	enemy_HP_num.grapic_data_struct.radius = 0;
	enemy_HP_num.grapic_data_struct.end_x = 0;
	enemy_HP_num.grapic_data_struct.end_y = 0;
	
	enemy_HP_num.header.data_cmd_id = 0x110; //绘制字符
	enemy_HP_num.header.sender_ID = game_robot_status.robot_id;
	enemy_HP_num.header.receiver_ID = game_robot_status.robot_id + 0x100;
	enemy_HP_num.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
 //2/6-green,1-yellow,0-main,3-orange
	enemy_HP_num.grapic_data_struct.radius=show_robot_HP;
	total_len = fill_tx_buffer((uint8_t*)&enemy_HP_num,sizeof(enemy_HP_num));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
}

void ammo_init(){
	//整型数
	uint16_t total_len=0;
	ammo.grapic_data_struct.graphic_name[0] = 0x20;
	ammo.grapic_data_struct.graphic_name[1] = 0x11;
	ammo.grapic_data_struct.graphic_name[2] = 0x12;

	ammo.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	ammo.grapic_data_struct.graphic_tpye = 6; //0-line 2- circle 7-char
	ammo.grapic_data_struct.layer = DYNAMIC_LAYER;
	ammo.grapic_data_struct.color = COLOR_CYAN; //2/6-green,1-yellow,0-main,3-orange
	ammo.grapic_data_struct.start_angle = 40;
	ammo.grapic_data_struct.end_angle = 0;
	ammo.grapic_data_struct.width = 4;

	ammo.grapic_data_struct.start_x = 910;
	ammo.grapic_data_struct.start_y = 700;
	ammo.grapic_data_struct.radius = 0;
	ammo.grapic_data_struct.end_x = 0;
	ammo.grapic_data_struct.end_y = 0;
	
	ammo.header.data_cmd_id = 0x110; //绘制字符
	ammo.header.sender_ID = game_robot_status.robot_id;
	ammo.header.receiver_ID = game_robot_status.robot_id + 0x100;
	ammo.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
 //2/6-green,1-yellow,0-main,3-orange
	ammo.grapic_data_struct.radius=current_shoot_quantity;
	total_len = fill_tx_buffer((uint8_t*)&ammo,sizeof(ammo));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
}

void shoot_speed_init(){
	//浮点数
	uint16_t total_len=0;
	shoot_speed.grapic_data_struct.graphic_name[0] = 0x20;
	shoot_speed.grapic_data_struct.graphic_name[1] = 0x09;
	shoot_speed.grapic_data_struct.graphic_name[2] = 0x12;

	shoot_speed.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	shoot_speed.grapic_data_struct.graphic_tpye = 5; //0-line 2- circle 7-char
	shoot_speed.grapic_data_struct.layer = DYNAMIC_LAYER;
	shoot_speed.grapic_data_struct.color = COLOR_CYAN; //2/6-green,1-yellow,0-main,3-orange
	shoot_speed.grapic_data_struct.start_angle = 40;
	shoot_speed.grapic_data_struct.end_angle = 2;
	shoot_speed.grapic_data_struct.width = 4;

	shoot_speed.grapic_data_struct.start_x = 1700;
	shoot_speed.grapic_data_struct.start_y = 540;
	shoot_speed.grapic_data_struct.radius = 0;
	shoot_speed.grapic_data_struct.end_x = 0;
	shoot_speed.grapic_data_struct.end_y = 0;
	
	shoot_speed.header.data_cmd_id = 0x110; //绘制字符
	shoot_speed.header.sender_ID = game_robot_status.robot_id;
	shoot_speed.header.receiver_ID = game_robot_status.robot_id + 0x100;
	shoot_speed.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
 //2/6-green,1-yellow,0-main,3-orange
	shoot_speed.grapic_data_struct.radius=shoot_speed_set*10;
	total_len = fill_tx_buffer((uint8_t*)&shoot_speed,sizeof(shoot_speed));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
}


void spin_fric_dot_init(){
	spin_fric_dot.grapic_data_struct[0].graphic_name[0] = 0x22;
	spin_fric_dot.grapic_data_struct[0].graphic_name[1] = 0x21;
	spin_fric_dot.grapic_data_struct[0].graphic_name[2] = 0x22;
	//小陀螺指示器
	spin_fric_dot.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	spin_fric_dot.grapic_data_struct[0].graphic_tpye = GRAPHIC_CIRCLE; //0-line 2- circle 7-char
	spin_fric_dot.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	spin_fric_dot.grapic_data_struct[0].color = COLOR_ORANGE; //2/6-green,1-yellow,0-main,3-orange
	spin_fric_dot.grapic_data_struct[0].start_angle = 0;
	spin_fric_dot.grapic_data_struct[0].end_angle = 0;
	spin_fric_dot.grapic_data_struct[0].width = 10;

	spin_fric_dot.grapic_data_struct[0].start_x = 680;
	spin_fric_dot.grapic_data_struct[0].start_y = 680;
	spin_fric_dot.grapic_data_struct[0].radius = 15;
	spin_fric_dot.grapic_data_struct[0].end_x = 0;
	spin_fric_dot.grapic_data_struct[0].end_y = 0;
	memcpy(&dynamic_layer_data_extra.grapic_data_struct[0]
	  ,&spin_fric_dot.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	
	spin_fric_dot.grapic_data_struct[1].graphic_name[0] = 0x22;
	spin_fric_dot.grapic_data_struct[1].graphic_name[1] = 0x21;
	spin_fric_dot.grapic_data_struct[1].graphic_name[2] = 0x20;
	
	spin_fric_dot.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	spin_fric_dot.grapic_data_struct[1].graphic_tpye = GRAPHIC_CIRCLE; //0-line 2- circle 7-char
	spin_fric_dot.grapic_data_struct[1].layer = DYNAMIC_LAYER;
	spin_fric_dot.grapic_data_struct[1].color = COLOR_ORANGE; //2/6-green,1-yellow,0-main,3-orange
	spin_fric_dot.grapic_data_struct[1].start_angle = 0;
	spin_fric_dot.grapic_data_struct[1].end_angle = 0;
	spin_fric_dot.grapic_data_struct[1].width = 10;

	spin_fric_dot.grapic_data_struct[1].start_x = 680;
	spin_fric_dot.grapic_data_struct[1].start_y = 400;
	spin_fric_dot.grapic_data_struct[1].radius = 15;
	spin_fric_dot.grapic_data_struct[1].end_x = 0;
	spin_fric_dot.grapic_data_struct[1].end_y = 0;
	memcpy(&dynamic_layer_data_extra.grapic_data_struct[1]
		,&spin_fric_dot.grapic_data_struct[1],sizeof(graphic_data_struct_t));
	
}
void grenade_aim_init(){
  grenade_aim.grapic_data_struct[0].graphic_name[0] = 0x22;
	grenade_aim.grapic_data_struct[0].graphic_name[1] = 0x22;
	grenade_aim.grapic_data_struct[0].graphic_name[2] = 0x22;
	//最大横线左
	grenade_aim.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	grenade_aim.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	grenade_aim.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	grenade_aim.grapic_data_struct[0].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	grenade_aim.grapic_data_struct[0].start_angle = 0;
	grenade_aim.grapic_data_struct[0].end_angle = 0;
	grenade_aim.grapic_data_struct[0].width = 5;

	grenade_aim.grapic_data_struct[0].start_x = 800;
	grenade_aim.grapic_data_struct[0].start_y = 450;
	grenade_aim.grapic_data_struct[0].radius =0;
	grenade_aim.grapic_data_struct[0].end_x = 930;
	grenade_aim.grapic_data_struct[0].end_y = 450;
	memcpy(&dynamic_layer_data_extra.grapic_data_struct[2]
		,&grenade_aim.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	
	
	grenade_aim.grapic_data_struct[1].graphic_name[0] = 0x20;
	grenade_aim.grapic_data_struct[1].graphic_name[1] = 0x22;
	grenade_aim.grapic_data_struct[1].graphic_name[2] = 0x22;
	//第二大横线
	grenade_aim.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	grenade_aim.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	grenade_aim.grapic_data_struct[1].layer = DYNAMIC_LAYER;
	grenade_aim.grapic_data_struct[1].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	grenade_aim.grapic_data_struct[1].start_angle = 0;
	grenade_aim.grapic_data_struct[1].end_angle = 0;
	grenade_aim.grapic_data_struct[1].width = 5;

	grenade_aim.grapic_data_struct[1].start_x = 890;
	grenade_aim.grapic_data_struct[1].start_y = 400;
	grenade_aim.grapic_data_struct[1].radius = 0;
	grenade_aim.grapic_data_struct[1].end_x = 1030;
	grenade_aim.grapic_data_struct[1].end_y = 400;
	memcpy(&dynamic_layer_data_extra.grapic_data_struct[3]
		,&grenade_aim.grapic_data_struct[1],sizeof(graphic_data_struct_t));
		
	  grenade_aim1.grapic_data_struct[0].graphic_name[0] = 0x19; //第三大横线
	grenade_aim1.grapic_data_struct[0].graphic_name[1] = 0x22;
	grenade_aim1.grapic_data_struct[0].graphic_name[2] = 0x22;
	grenade_aim1.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	grenade_aim1.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	grenade_aim1.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	grenade_aim1.grapic_data_struct[0].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	grenade_aim1.grapic_data_struct[0].start_angle = 0;
	grenade_aim1.grapic_data_struct[0].end_angle = 0;
	grenade_aim1.grapic_data_struct[0].width = 5;

	grenade_aim1.grapic_data_struct[0].start_x = 905;
	grenade_aim1.grapic_data_struct[0].start_y = 350;
	grenade_aim1.grapic_data_struct[0].radius = 0;
	grenade_aim1.grapic_data_struct[0].end_x = 1015;
	grenade_aim1.grapic_data_struct[0].end_y = 350;
	memcpy(&dynamic_layer_data_extra.grapic_data_struct[4]
		,&grenade_aim1.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	
	grenade_aim1.grapic_data_struct[1].graphic_name[0] = 0x18;
	grenade_aim1.grapic_data_struct[1].graphic_name[1] = 0x22;
	grenade_aim1.grapic_data_struct[1].graphic_name[2] = 0x22;
	//第四大横线
	grenade_aim1.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	grenade_aim1.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	grenade_aim1.grapic_data_struct[1].layer = DYNAMIC_LAYER;
	grenade_aim1.grapic_data_struct[1].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	grenade_aim1.grapic_data_struct[1].start_angle = 0;
	grenade_aim1.grapic_data_struct[1].end_angle = 0;
	grenade_aim1.grapic_data_struct[1].width = 5;

	grenade_aim1.grapic_data_struct[1].start_x = 925;
	grenade_aim1.grapic_data_struct[1].start_y =300;
	grenade_aim1.grapic_data_struct[1].radius = 0;
	grenade_aim1.grapic_data_struct[1].end_x = 995;
	grenade_aim1.grapic_data_struct[1].end_y = 300;
	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[0]
		,&grenade_aim1.grapic_data_struct[1],sizeof(graphic_data_struct_t));
		
	grenade_aim2.grapic_data_struct[0].graphic_name[0] = 0x17;
	grenade_aim2.grapic_data_struct[0].graphic_name[1] = 0x22;
	grenade_aim2.grapic_data_struct[0].graphic_name[2] = 0x22;
	//最大横线右
	grenade_aim2.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	grenade_aim2.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	grenade_aim2.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	grenade_aim2.grapic_data_struct[0].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	grenade_aim2.grapic_data_struct[0].start_angle = 0;
	grenade_aim2.grapic_data_struct[0].end_angle = 0;
	grenade_aim2.grapic_data_struct[0].width = 5;

	grenade_aim2.grapic_data_struct[0].start_x = 1120;
	grenade_aim2.grapic_data_struct[0].start_y = 450;
	grenade_aim2.grapic_data_struct[0].radius =0;
	grenade_aim2.grapic_data_struct[0].end_x = 990;
	grenade_aim2.grapic_data_struct[0].end_y = 450;
	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[1]
		,&grenade_aim2.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	
		//第五大横线
		grenade_aim2.grapic_data_struct[1].graphic_name[0] = 0x16;
	grenade_aim2.grapic_data_struct[1].graphic_name[1] = 0x22;
	grenade_aim2.grapic_data_struct[1].graphic_name[2] = 0x22;
	grenade_aim2.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	grenade_aim2.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	grenade_aim2.grapic_data_struct[1].layer = DYNAMIC_LAYER;
	grenade_aim2.grapic_data_struct[1].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	grenade_aim2.grapic_data_struct[1].start_angle = 0;
	grenade_aim2.grapic_data_struct[1].end_angle = 0;
	grenade_aim2.grapic_data_struct[1].width = 5;

	grenade_aim2.grapic_data_struct[1].start_x = 940;
	grenade_aim2.grapic_data_struct[1].start_y =250;
	grenade_aim2.grapic_data_struct[1].radius = 0;
	grenade_aim2.grapic_data_struct[1].end_x = 980;
	grenade_aim2.grapic_data_struct[1].end_y = 250;
	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[2]
		,&grenade_aim2.grapic_data_struct[1],sizeof(graphic_data_struct_t));

	battle_45degree.grapic_data_struct.graphic_name[0] = 0x01;
	battle_45degree.grapic_data_struct.graphic_name[1] = 0x01;
	battle_45degree.grapic_data_struct.graphic_name[2] = 0x22;
	battle_45degree.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	battle_45degree.grapic_data_struct.graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	battle_45degree.grapic_data_struct.layer = DYNAMIC_LAYER;
	battle_45degree.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	battle_45degree.grapic_data_struct.start_angle = 0;
	battle_45degree.grapic_data_struct.end_angle = 0;
	battle_45degree.grapic_data_struct.width = 5;

	battle_45degree.grapic_data_struct.start_x = 960;
	battle_45degree.grapic_data_struct.start_y =400;
	battle_45degree.grapic_data_struct.radius = 0;
	battle_45degree.grapic_data_struct.end_x = 960;
	battle_45degree.grapic_data_struct.end_y = 150;
	
}

void enemy_HP_data_init(){
	 
	enemy_HP_data.grapic_data_struct[0].graphic_name[0] = 0x15;
	enemy_HP_data.grapic_data_struct[0].graphic_name[1] = 0x10;
	enemy_HP_data.grapic_data_struct[0].graphic_name[2] = 0x10;
	
	enemy_HP_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	enemy_HP_data.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	enemy_HP_data.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	enemy_HP_data.grapic_data_struct[0].color = COLOR_PURPLE; //2/6-green,1-yellow,0-main,3-orange
	enemy_HP_data.grapic_data_struct[0].start_angle = 0;
	enemy_HP_data.grapic_data_struct[0].end_angle = 0;
	enemy_HP_data.grapic_data_struct[0].width = HP_BAR_WIDTH*2;
	//(460,350)(460,650)
	enemy_HP_data.grapic_data_struct[0].start_x = HP_BAR_LEFT;
	enemy_HP_data.grapic_data_struct[0].start_y = HP_BAR_HORIZ ;
	enemy_HP_data.grapic_data_struct[0].radius = 0;
	enemy_HP_data.grapic_data_struct[0].end_x = HP_BAR_LEFT+HP_BAR_LEN;
	enemy_HP_data.grapic_data_struct[0].end_y = HP_BAR_HORIZ ;
	memcpy(&dynamic_layer_data_grenade.grapic_data_struct[3]
		,&enemy_HP_data.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	  
  enemy_HP_data.grapic_data_struct[1].graphic_name[0] = 0x16;
	enemy_HP_data.grapic_data_struct[1].graphic_name[1] = 0x10;
	enemy_HP_data.grapic_data_struct[1].graphic_name[2] = 0x10;
	
	enemy_HP_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	enemy_HP_data.grapic_data_struct[1].graphic_tpye = GRAPHIC_SQUARE; //0-line 2- circle 7-char
	enemy_HP_data.grapic_data_struct[1].layer = DYNAMIC_LAYER;
	enemy_HP_data.grapic_data_struct[1].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	enemy_HP_data.grapic_data_struct[1].start_angle = 0;
	enemy_HP_data.grapic_data_struct[1].end_angle = 0;
	enemy_HP_data.grapic_data_struct[1].width = 2;
	enemy_HP_data.grapic_data_struct[1].start_x = HP_BAR_LEFT-MARGIN;  //边框5，条宽度10
	enemy_HP_data.grapic_data_struct[1].start_y = HP_BAR_HORIZ +HP_BAR_WIDTH+MARGIN;
	enemy_HP_data.grapic_data_struct[1].radius = 0;
	enemy_HP_data.grapic_data_struct[1].end_x = HP_BAR_LEFT+HP_BAR_LEN+MARGIN;
	enemy_HP_data.grapic_data_struct[1].end_y = HP_BAR_HORIZ -HP_BAR_WIDTH-MARGIN;; //高度700
	
}



void voltage_bar_data_init(){

	// voltage_bar_data.grapic_data_struct[0].graphic_name[0] = 0x20;
	// voltage_bar_data.grapic_data_struct[0].graphic_name[1] = 0x21;
	// voltage_bar_data.grapic_data_struct[0].graphic_name[2] = 0x21;
	
	// voltage_bar_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	// voltage_bar_data.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	// voltage_bar_data.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	// voltage_bar_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	// voltage_bar_data.grapic_data_struct[0].start_angle = 0;
	// voltage_bar_data.grapic_data_struct[0].end_angle = 0;
	// voltage_bar_data.grapic_data_struct[0].width = BAR_WIDTH*2;
	// //(460,350)(460,650)
	// voltage_bar_data.grapic_data_struct[0].start_x = BAR_LEFT;
	// voltage_bar_data.grapic_data_struct[0].start_y = BAR_HORIZ;
	// voltage_bar_data.grapic_data_struct[0].radius = 0;
	// voltage_bar_data.grapic_data_struct[0].end_x = BAR_RIGHT;
	// voltage_bar_data.grapic_data_struct[0].end_y = BAR_HORIZ;
	// memcpy(&dynamic_layer_data.grapic_data_struct[0]
	// 	,&voltage_bar_data.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	// //搞清楚这个动态图层啥意思
	// voltage_bar_data.grapic_data_struct[1].graphic_name[0] = 0x20;
	// voltage_bar_data.grapic_data_struct[1].graphic_name[1] = 0x20;
	// voltage_bar_data.grapic_data_struct[1].graphic_name[2] = 0x21;
	
	// voltage_bar_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	// voltage_bar_data.grapic_data_struct[1].graphic_tpye = GRAPHIC_SQUARE; //0-line 2- circle 7-char
	// voltage_bar_data.grapic_data_struct[1].layer = BACKGROUND_LAYER;
	// voltage_bar_data.grapic_data_struct[1].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	// voltage_bar_data.grapic_data_struct[1].start_angle = 0;
	// voltage_bar_data.grapic_data_struct[1].end_angle = 0;
	// voltage_bar_data.grapic_data_struct[1].width = 2;
	// voltage_bar_data.grapic_data_struct[1].start_x = BAR_LEFT-MARGIN;
	// voltage_bar_data.grapic_data_struct[1].start_y = BAR_HORIZ+BAR_WIDTH+MARGIN;
	// voltage_bar_data.grapic_data_struct[1].radius = 0;
	// voltage_bar_data.grapic_data_struct[1].end_x = BAR_RIGHT+MARGIN;
	// voltage_bar_data.grapic_data_struct[1].end_y = BAR_HORIZ-BAR_WIDTH-MARGIN;;
	memset(&voltage_bar_data,0,sizeof(voltage_bar_data));
	memset(&chassis_dir_data,0,sizeof(chassis_dir_data));
	voltage_bar_data.grapic_data_struct[0].graphic_name[0] = 0x20;
	voltage_bar_data.grapic_data_struct[0].graphic_name[1] = 0x20;
	voltage_bar_data.grapic_data_struct[0].graphic_name[2] = 0x21;

	//新ui
	voltage_bar_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	voltage_bar_data.grapic_data_struct[0].graphic_tpye = GRAPHIC_ARC;
	voltage_bar_data.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	voltage_bar_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	voltage_bar_data.grapic_data_struct[0].start_angle = 60;//更改起始角度
	voltage_bar_data.grapic_data_struct[0].end_angle = 120;//更改结束角度
	voltage_bar_data.grapic_data_struct[0].width = BAR_WIDTH;
	//(460,350)(460,650)
	voltage_bar_data.grapic_data_struct[0].start_x = MIDDLE_X;
	voltage_bar_data.grapic_data_struct[0].start_y = MIDDLE_Y;
	voltage_bar_data.grapic_data_struct[0].radius = 0;
	voltage_bar_data.grapic_data_struct[0].end_x = 350;
	voltage_bar_data.grapic_data_struct[0].end_y = 350;

	memcpy(&dynamic_layer_data.grapic_data_struct[0]
		,&voltage_bar_data.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	
	voltage_bar_data.grapic_data_struct[1].graphic_name[0] = 0x20;
	voltage_bar_data.grapic_data_struct[1].graphic_name[1] = 0x21;
	voltage_bar_data.grapic_data_struct[1].graphic_name[2] = 0x21;
	
	voltage_bar_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	voltage_bar_data.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	voltage_bar_data.grapic_data_struct[1].layer = BACKGROUND_LAYER;
	voltage_bar_data.grapic_data_struct[1].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	voltage_bar_data.grapic_data_struct[1].start_angle = 0;
	voltage_bar_data.grapic_data_struct[1].end_angle = 0;
	voltage_bar_data.grapic_data_struct[1].width = 2;
	voltage_bar_data.grapic_data_struct[1].start_x = (uint32_t)((350 + 10) * cosf(31*2*PI/360.0f) + MIDDLE_X);
	voltage_bar_data.grapic_data_struct[1].start_y = (uint32_t)((350 + 10) * sinf(31*2*PI/360.0f) + MIDDLE_Y);
	voltage_bar_data.grapic_data_struct[1].radius = 0;
	voltage_bar_data.grapic_data_struct[1].end_x = (uint32_t)((350 - 10) * cosf(31*2*PI/360.0f) + MIDDLE_X);
	voltage_bar_data.grapic_data_struct[1].end_y = (uint32_t)((350 - 10) * sinf(31*2*PI/360.0f) + MIDDLE_Y);
	
	chassis_dir_data.grapic_data_struct[0].graphic_name[0] = 0x20;
	chassis_dir_data.grapic_data_struct[0].graphic_name[1] = 0x21;
	chassis_dir_data.grapic_data_struct[0].graphic_name[2] = 0x22;
	
	chassis_dir_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	chassis_dir_data.grapic_data_struct[0].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	chassis_dir_data.grapic_data_struct[0].layer = DYNAMIC_LAYER;
	chassis_dir_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	chassis_dir_data.grapic_data_struct[0].start_angle = 0;
	chassis_dir_data.grapic_data_struct[0].end_angle = 0;
	chassis_dir_data.grapic_data_struct[0].width = 2;
	chassis_dir_data.grapic_data_struct[0].start_x = CHASSIS_DIR_X;
	chassis_dir_data.grapic_data_struct[0].start_y = CHASSIS_DIR_Y + LONG_BRANCH;
	chassis_dir_data.grapic_data_struct[0].radius = 0;
	chassis_dir_data.grapic_data_struct[0].end_x = CHASSIS_DIR_X;
	chassis_dir_data.grapic_data_struct[0].end_y = CHASSIS_DIR_Y - SHORT_BRANCH;
	
	
	chassis_dir_data.grapic_data_struct[1].graphic_name[0] = 0x20;
	chassis_dir_data.grapic_data_struct[1].graphic_name[1] = 0x21;
	chassis_dir_data.grapic_data_struct[1].graphic_name[2] = 0x23;
	
	chassis_dir_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	chassis_dir_data.grapic_data_struct[1].graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	chassis_dir_data.grapic_data_struct[1].layer = DYNAMIC_LAYER;
	chassis_dir_data.grapic_data_struct[1].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	chassis_dir_data.grapic_data_struct[1].start_angle = 0;
	chassis_dir_data.grapic_data_struct[1].end_angle = 0;
	chassis_dir_data.grapic_data_struct[1].width = 3;
	chassis_dir_data.grapic_data_struct[1].start_x = (CHASSIS_DIR_X - LONG_BRANCH);
	chassis_dir_data.grapic_data_struct[1].start_y = CHASSIS_DIR_Y;
	chassis_dir_data.grapic_data_struct[1].radius = 0;
	chassis_dir_data.grapic_data_struct[1].end_x = CHASSIS_DIR_X + LONG_BRANCH;
	chassis_dir_data.grapic_data_struct[1].end_y = CHASSIS_DIR_Y;
	memcpy(&dynamic_layer_data.grapic_data_struct[1]
		,&chassis_dir_data.grapic_data_struct[0],sizeof(graphic_data_struct_t));
	memcpy(&dynamic_layer_data.grapic_data_struct[2]
		,&chassis_dir_data.grapic_data_struct[1],sizeof(graphic_data_struct_t));

	
	state_indicator.grapic_data_struct.graphic_name[0] = 0x20;
	state_indicator.grapic_data_struct.graphic_name[1] = 0x21;
	state_indicator.grapic_data_struct.graphic_name[2] = 0x24;
	
	state_indicator.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	state_indicator.grapic_data_struct.graphic_tpye = GRAPHIC_LINE; //0-line 2- circle 7-char
	state_indicator.grapic_data_struct.layer = DYNAMIC_LAYER;
	state_indicator.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	state_indicator.grapic_data_struct.start_angle = 0;
	state_indicator.grapic_data_struct.end_angle = 0;
	state_indicator.grapic_data_struct.width = (INDIC_HALF_WIDTH*2);
	//(460,350)(460,650)
	state_indicator.grapic_data_struct.start_x = (CHASSIS_STATE_BASE_POS_X - INDIC_MARGIN - INDIC_LEN);
	state_indicator.grapic_data_struct.start_y = (CHASSIS_STATE_BASE_POS_Y - INDIC_HALF_WIDTH);
	state_indicator.grapic_data_struct.radius = 0;
	state_indicator.grapic_data_struct.end_x = (CHASSIS_STATE_BASE_POS_X - INDIC_MARGIN);
	state_indicator.grapic_data_struct.end_y = (CHASSIS_STATE_BASE_POS_Y - INDIC_HALF_WIDTH);
	memcpy(&dynamic_layer_data.grapic_data_struct[3]
		,&state_indicator.grapic_data_struct,sizeof(graphic_data_struct_t));

	vision_ref_data.grapic_data_struct.graphic_name[0] = 0x20;
	vision_ref_data.grapic_data_struct.graphic_name[1] = 0x21;
	vision_ref_data.grapic_data_struct.graphic_name[2] = 0x25;

	vision_ref_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	vision_ref_data.grapic_data_struct.graphic_tpye = GRAPHIC_CIRCLE; //0-line 2- circle 7-char
	vision_ref_data.grapic_data_struct.layer = DYNAMIC_LAYER;
	vision_ref_data.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	vision_ref_data.grapic_data_struct.start_angle = 0;
	vision_ref_data.grapic_data_struct.end_angle = 0;
	vision_ref_data.grapic_data_struct.width = 3;
	//(460,350)(460,650)
	vision_ref_data.grapic_data_struct.start_x = MIDDLE_X;
	vision_ref_data.grapic_data_struct.start_y = MIDDLE_Y;
	vision_ref_data.grapic_data_struct.radius = 100;
	vision_ref_data.grapic_data_struct.end_x = 0;
	vision_ref_data.grapic_data_struct.end_y = 0;
	memcpy(&dynamic_layer_data.grapic_data_struct[4]
		,&vision_ref_data.grapic_data_struct,sizeof(graphic_data_struct_t));
}


void ui_graphic_delete(uint8_t operate_tpye, uint8_t layer){
	uint16_t total_len = 0;
	memset(&delete_data,0,sizeof(delete_data));
	delete_data.header.data_cmd_id = 0x100;
	delete_data.header.sender_ID = game_robot_status.robot_id;
	delete_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	
	delete_data.layer = layer;
	delete_data.operate_tpye = operate_tpye;
	
	total_len = fill_tx_buffer((uint8_t*)&delete_data,sizeof(delete_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
}



void init_ui_static(void){
	memset(&voltage_bar_data,0,sizeof(voltage_bar_data));
	//voltage_bar_data.grapic_data_struct[0]
	voltage_bar_data_init();
	char_data_init();
	spin_fric_dot_init();
	grenade_aim_init();
	enemy_HP_data_init();
	enemy_HP_num_init();
	ammo_init();
}

void update_background(void){  //静态图层的设置
	uint16_t total_len = 0;
	voltage_bar_data.header.data_cmd_id = 0x102; //绘制两个图形
	voltage_bar_data.header.sender_ID = game_robot_status.robot_id;
	voltage_bar_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	voltage_bar_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	voltage_bar_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	total_len = fill_tx_buffer((uint8_t*)&voltage_bar_data,sizeof(voltage_bar_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
  chassis_dir_data.header.data_cmd_id = 0x102;
	chassis_dir_data.header.sender_ID = game_robot_status.robot_id;
	chassis_dir_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	chassis_dir_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	chassis_dir_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	total_len = fill_tx_buffer((uint8_t*)&chassis_dir_data,sizeof(chassis_dir_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	enemy_HP_data.header.data_cmd_id = 0x102; //绘制两个图形
	enemy_HP_data.header.sender_ID = game_robot_status.robot_id;
	enemy_HP_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	enemy_HP_data.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	enemy_HP_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	 if(vision_ctrl_data.target_found)
	  enemy_HP_data.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	 else
		enemy_HP_data.grapic_data_struct[1].operate_tpye = OP_TYPE_DEL;
	total_len = fill_tx_buffer((uint8_t*)&enemy_HP_data,sizeof(enemy_HP_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	
	// spin_fric_dot.header.data_cmd_id = 0x102; //绘制两个图形
	// spin_fric_dot.header.sender_ID = game_robot_status.robot_id;
	// spin_fric_dot.header.receiver_ID = game_robot_status.robot_id + 0x100;
	// spin_fric_dot.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	// spin_fric_dot.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	// total_len = fill_tx_buffer((uint8_t*)&spin_fric_dot,sizeof(spin_fric_dot));
	// UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	

	
	state_indicator.header.data_cmd_id = 0x101; //绘制一个图形
	state_indicator.header.sender_ID = game_robot_status.robot_id;
	state_indicator.header.receiver_ID = game_robot_status.robot_id + 0x100;
	state_indicator.grapic_data_struct.operate_tpye =OP_TYPE_ADD;
	total_len = fill_tx_buffer((uint8_t*)&state_indicator,sizeof(state_indicator));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);

	battle_45degree.header.data_cmd_id = 0x101; //绘制一个图形
	battle_45degree.header.sender_ID = game_robot_status.robot_id;
	battle_45degree.header.receiver_ID = game_robot_status.robot_id + 0x100;
	
	if( battle_45degreee)
	  battle_45degree.grapic_data_struct.operate_tpye =OP_TYPE_ADD;
	else if(! battle_45degreee)
		battle_45degree.grapic_data_struct.operate_tpye =OP_TYPE_DEL;
	total_len = fill_tx_buffer((uint8_t*)&battle_45degree,sizeof(battle_45degree));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	char_data.header.data_cmd_id = 0x110; //绘制字符
	char_data.header.sender_ID = game_robot_status.robot_id;
	char_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	char_data.grapic_data_struct.color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	
	//三个字符UI（这里才初始化） 为啥能一次三个
	char_data.grapic_data_struct.graphic_name[2] = 0x20;
	char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
	char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y;
	char_data.grapic_data_struct.start_angle = 16;
	char_data.grapic_data_struct.end_angle = strlen(state_text);
	memset(char_data.data,0,30);
	memcpy(char_data.data,state_text,strlen(state_text));
	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	// char_data.grapic_data_struct.graphic_name[2] = 0x21;
	// char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
	// char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y;
	// char_data.grapic_data_struct.start_angle = 12;
	// char_data.grapic_data_struct.end_angle = strlen(chassis_state_text);
	// memset(char_data.data,0,30);
	// memcpy(char_data.data,chassis_state_text,strlen(chassis_state_text));
	// total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	// UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	// char_data.grapic_data_struct.graphic_name[2] = 0x22;
	// char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
	// char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y - 60;
	// char_data.grapic_data_struct.start_angle = 12;
	// char_data.grapic_data_struct.end_angle = strlen(aim_state_text);
	// memset(char_data.data,0,30);
	// memcpy(char_data.data,aim_state_text,strlen(aim_state_text));
	// total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	// UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	//左侧小陀螺状态指示器
	char_data.grapic_data_struct.graphic_name[2] = 0x23;
	char_data.grapic_data_struct.start_x = 560;
	char_data.grapic_data_struct.start_y = 680;
	char_data.grapic_data_struct.start_angle = 20;
	char_data.grapic_data_struct.end_angle = strlen(spin_state_text);
	memset(char_data.data,0,30);
	memcpy(char_data.data,spin_state_text,strlen(spin_state_text));
	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	//左侧摩擦轮指示器
	char_data.grapic_data_struct.graphic_name[2] = 0x24;
	char_data.grapic_data_struct.start_x = 560;
	char_data.grapic_data_struct.start_y = 400;
	char_data.grapic_data_struct.start_angle = 20;
	char_data.grapic_data_struct.end_angle = strlen(fric_state_text);
	memset(char_data.data,0,30);
	memcpy(char_data.data,fric_state_text,strlen(fric_state_text));
	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	//弹舱盖指示器
	char_data.grapic_data_struct.graphic_name[2] = 0x25;
	char_data.grapic_data_struct.start_x = 1000;
	char_data.grapic_data_struct.start_y = 300;
	char_data.grapic_data_struct.start_angle = 100;
	char_data.grapic_data_struct.end_angle = strlen(cover_text);
	char_data.grapic_data_struct.width=10;
	memset(char_data.data,0,30);
	memcpy(char_data.data,cover_text,strlen(cover_text));
	if(cover_state)
		char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	else if(cover_state==0)
		char_data.grapic_data_struct.operate_tpye = OP_TYPE_DEL;
	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	char_data.grapic_data_struct.width=2;
	char_data.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	
	char_data.grapic_data_struct.graphic_name[2] = 0x24;
	char_data.grapic_data_struct.start_x = 560;
	char_data.grapic_data_struct.start_y = 400;
	char_data.grapic_data_struct.start_angle = 20;
	char_data.grapic_data_struct.end_angle = strlen(fric_state_text);
	memset(char_data.data,0,30);
	memcpy(char_data.data,fric_state_text,strlen(fric_state_text));
	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	

 enemy_HP_num.header.data_cmd_id = 0x110; //绘制字符
	enemy_HP_num.header.sender_ID = game_robot_status.robot_id;
	enemy_HP_num.header.receiver_ID = game_robot_status.robot_id + 0x100;
	if(vision_ctrl_data.target_found)
		enemy_HP_num.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
	else
		enemy_HP_num.grapic_data_struct.operate_tpye = OP_TYPE_DEL;
 //2/6-green,1-yellow,0-main,3-orange
	enemy_HP_num.grapic_data_struct.radius=show_robot_HP;
	total_len = fill_tx_buffer((uint8_t*)&enemy_HP_num,sizeof(enemy_HP_num));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	if(vision_ctrl_data.target_found){
		enemy_HP_num.grapic_data_struct.operate_tpye = OP_TYPE_MOD;
 //2/6-green,1-yellow,0-main,3-orange
		enemy_HP_num.grapic_data_struct.radius=show_robot_HP;
		total_len = fill_tx_buffer((uint8_t*)&enemy_HP_num,sizeof(enemy_HP_num));
		UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	}

	ammo.header.data_cmd_id = 0x110; //绘制字符
	ammo.header.sender_ID = game_robot_status.robot_id;
	ammo.header.receiver_ID = game_robot_status.robot_id + 0x100;
	ammo.grapic_data_struct.operate_tpye = OP_TYPE_ADD;
 //2/6-green,1-yellow,0-main,3-orange
	ammo.grapic_data_struct.radius = current_shoot_quantity;
	total_len = fill_tx_buffer((uint8_t*)&ammo,sizeof(ammo));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	ammo.header.data_cmd_id = 0x110; //绘制字符
	ammo.header.sender_ID = game_robot_status.robot_id;
	ammo.header.receiver_ID = game_robot_status.robot_id + 0x100;
	ammo.grapic_data_struct.operate_tpye = OP_TYPE_MOD;
 //2/6-green,1-yellow,0-main,3-orange
	ammo.grapic_data_struct.radius = current_shoot_quantity;
	total_len = fill_tx_buffer((uint8_t*)&ammo,sizeof(ammo));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
//	air_factor_data.header.data_cmd_id = 0x101;
//	air_factor_data.header.sender_ID = game_robot_status.robot_id;
//	air_factor_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	air_factor_data.grapic_data_struct.operate_tpye =OP_TYPE_ADD;
//	total_len = fill_tx_buffer((uint8_t*)&air_factor_data,sizeof(air_factor_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
}

#define HURT_ARC_LEN 10


void update_ui(float cap_voltage,float relative_angle,int32_t air_factor){
	uint16_t total_len = 0;
	input_HP();
	dynamic_layer_data.header.data_cmd_id = 0x103;
	dynamic_layer_data.header.sender_ID = game_robot_status.robot_id;
	dynamic_layer_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	
	dynamic_layer_data_extra.header.data_cmd_id = 0x103;
	dynamic_layer_data_extra.header.sender_ID = game_robot_status.robot_id;
	dynamic_layer_data_extra.header.receiver_ID = game_robot_status.robot_id + 0x100;
	
	dynamic_layer_data_grenade.header.data_cmd_id = 0x103;
	dynamic_layer_data_grenade.header.sender_ID = game_robot_status.robot_id;
	dynamic_layer_data_grenade.header.receiver_ID = game_robot_status.robot_id + 0x100;
	
	dynamic_layer_data_grenade.grapic_data_struct[3].end_x=HP_BAR_LEFT+ ((show_robot_HP+0.01f) / (show_robot_HP_max+0.01f))*HP_BAR_LEN; 
	
	if(cap_voltage < 14.0f){
		dynamic_layer_data.grapic_data_struct[0].color = COLOR_PURPLE; //2/6-green,1-yellow,0-main,3-orange
	}else if(cap_voltage < 18.0f){
		dynamic_layer_data.grapic_data_struct[0].color = COLOR_YELLOW; //2/6-green,1-yellow,0-main,3-orange
	}else{
		dynamic_layer_data.grapic_data_struct[0].color = COLOR_GREEN; //2/6-green,1-yellow,0-main,3-orange
	}
	LIMIT_MIN_MAX(cap_voltage, 12.0f, 24.5f);
	LIMIT_MIN_MAX(cap_data.input_voltage, 20.0f, 25.0f);
	dynamic_layer_data.grapic_data_struct[0].start_angle = (uint32_t)(120 - ((cap_voltage - 12.0f) / (cap_data.input_voltage - 14.1f))*60); //350 +300
	LIMIT_MIN_MAX(dynamic_layer_data.grapic_data_struct[0].start_angle, 60, 120);
	
	dynamic_layer_data.grapic_data_struct[0].operate_tpye = OP_TYPE_MOD;
	
	float sin_ang = sinf(2*PI*relative_angle / 360.0f);
	float cos_ang = cosf(2*PI*relative_angle / 360.0f);

	dynamic_layer_data.grapic_data_struct[1].start_x = CHASSIS_DIR_X+sin_ang*LONG_BRANCH;
	dynamic_layer_data.grapic_data_struct[1].start_y = CHASSIS_DIR_Y+cos_ang*LONG_BRANCH;
	dynamic_layer_data.grapic_data_struct[1].end_x = CHASSIS_DIR_X-sin_ang*SHORT_BRANCH;
	dynamic_layer_data.grapic_data_struct[1].end_y = CHASSIS_DIR_Y-cos_ang*SHORT_BRANCH;
	
	dynamic_layer_data.grapic_data_struct[2].start_x = CHASSIS_DIR_X-cos_ang*LONG_BRANCH;
	dynamic_layer_data.grapic_data_struct[2].start_y = CHASSIS_DIR_Y+sin_ang*LONG_BRANCH;
	dynamic_layer_data.grapic_data_struct[2].end_x = CHASSIS_DIR_X+cos_ang*LONG_BRANCH;
	dynamic_layer_data.grapic_data_struct[2].end_y = CHASSIS_DIR_Y-sin_ang*LONG_BRANCH;
	
	dynamic_layer_data.grapic_data_struct[0].operate_tpye = OP_TYPE_MOD;
	

	
	
	dynamic_layer_data.grapic_data_struct[1].operate_tpye = OP_TYPE_MOD;
	dynamic_layer_data.grapic_data_struct[2].operate_tpye = OP_TYPE_MOD;
	
	dynamic_layer_data.grapic_data_struct[3].operate_tpye = OP_TYPE_MOD;
	//dynamic_layer_data.grapic_data_struct[3].color = COLOR_GREEN;
	dynamic_layer_data.grapic_data_struct[3].start_y = indicator_y;
	dynamic_layer_data.grapic_data_struct[3].end_y = indicator_y;
	
	dynamic_layer_data.grapic_data_struct[4].operate_tpye = OP_TYPE_MOD;
	dynamic_layer_data_grenade.grapic_data_struct[3].operate_tpye = OP_TYPE_MOD;

	
	//大型状态指示器
	if(chassis_spin_state == SPINNING){
		dynamic_layer_data_extra.grapic_data_struct[0].operate_tpye = OP_TYPE_ADD;
	}
	else{
		dynamic_layer_data_extra.grapic_data_struct[0].operate_tpye = OP_TYPE_DEL;
	}
	
	if(fric_state)
    dynamic_layer_data_extra.grapic_data_struct[1].operate_tpye = OP_TYPE_ADD;
	else if(!fric_state)
	   dynamic_layer_data_extra.grapic_data_struct[1].operate_tpye = OP_TYPE_DEL;
	
	// dynamic_layer_data_extra.grapic_data_struct[0].operate_tpye = OP_TYPE_MOD;
	// dynamic_layer_data_extra.grapic_data_struct[1].operate_tpye = OP_TYPE_MOD;
	
	
	total_len = fill_tx_buffer((uint8_t*)&dynamic_layer_data_extra,sizeof(dynamic_layer_data_extra));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	total_len = fill_tx_buffer((uint8_t*)&dynamic_layer_data,sizeof(dynamic_layer_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	total_len = fill_tx_buffer((uint8_t*)&dynamic_layer_data_grenade,sizeof(dynamic_layer_data_grenade));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);

	char_data.header.data_cmd_id = 0x110;
	char_data.header.sender_ID = game_robot_status.robot_id;
	char_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
	char_data.grapic_data_struct.graphic_name[2] = 0x20;
	char_data.grapic_data_struct.operate_tpye = OP_TYPE_MOD;
	char_data.grapic_data_struct.start_x = CHASSIS_STATE_BASE_POS_X;
	char_data.grapic_data_struct.start_y = CHASSIS_STATE_BASE_POS_Y;
	char_data.grapic_data_struct.start_angle = 16;
	char_data.grapic_data_struct.end_angle = strlen(state_text);
	if(cover_state) memcpy(state_text+4, "1", 1);
	else memcpy(state_text+4, "0", 1);
	memcpy(char_data.data,state_text,strlen(state_text));
	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
	
	
	//状态字符   
//	char_data.header.data_cmd_id = 0x110;
//	char_data.header.sender_ID = game_robot_status.robot_id;
//	char_data.header.receiver_ID = game_robot_status.robot_id + 0x100;
//	char_data.grapic_data_struct.operate_tpye = OP_TYPE_MOD;
//	char_data.grapic_data_struct.graphic_name[2] = 0x20;
//	char_data.grapic_data_struct.start_x = 1100;
//	char_data.grapic_data_struct.start_y = 100;
//	char_data.grapic_data_struct.start_angle = 18;
//	char_data.grapic_data_struct.end_angle = strlen(state_text);
//	if(motor_state & 0x01) memcpy(state_text+2, "1", 1);
//	else memcpy(state_text+2, "0", 1);
//	if(motor_state & 0x02) memcpy(state_text+6, "1", 1);
//	else memcpy(state_text+6, "0", 1);
//	if(motor_state & 0x04) memcpy(state_text+10, "1", 1);
//	else memcpy(state_text+10, "0", 1);
//	if(reload_flag) memcpy(state_text+16, "1", 1);
//	else memcpy(state_text+16, "0", 1);
//	if(fric_state) memcpy(state_text+22, "1", 1);
//	else memcpy(state_text+22, "0", 1);
//	if(vision_ctrl_data.target_found) memcpy(state_text+27, "1", 1);
//	else memcpy(state_text+27, "0", 1);
//	memcpy(char_data.data,state_text,strlen(state_text));
//	if(char_data.data[CHASSIS_STATE] == '?' 
//		||char_data.data[GIMBAL_STATE] == '?' 
//		|| char_data.data[SHOOT_STATE] == '?' 
//		|| char_data.data[IMU_STATE] == '?' ){
//			char_data.grapic_data_struct.color = COLOR_YELLOW;
//		}else{
//			char_data.grapic_data_struct.color = COLOR_GREEN;
//		}
//	total_len = fill_tx_buffer((uint8_t*)&char_data,sizeof(char_data));
//	UI_UART_SEND(&UI_HUART,tx_buffer,total_len);
		
	
}

